package com.lwh.springboot.service.impl;

import com.lwh.springboot.mapper.InsureMapper;
import com.lwh.springboot.pojo.entity.Insure;
import com.lwh.springboot.pojo.vo.InsureVO;
import com.lwh.springboot.service.IInsureService;
import com.lwh.springboot.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

// Alt+Enter:快速修复一些错误
@Service
public class InsureServiceImpl implements IInsureService {
    @Autowired
    private InsureMapper insureMapper;

    //业务
    @Override
    public List<Insure> selectAll() {
        List<Insure> list = insureMapper.selectAll();
        return list;
    }

    @Override
    public void deleteById(Integer id) {
        insureMapper.deleteById(id);
    }

    @Override
    public void add(Insure insure) {
        insureMapper.add(insure);
    }

    @Override
    public Insure selectById(Integer id) {
        return insureMapper.selectById(id);
    }

    @Override
    public void update(Insure insure) {
        insureMapper.update(insure);
    }

    // totalCount:101
    // pageSize:10
    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        // limit
        int offset = (pageNo - 1) * pageSize;
        //查找当前也数据
        List<InsureVO> list = insureMapper.selectByPage(offset, pageSize);
        //查找总的数量，目的是为了算总的页数totalPage
        int totalCount = insureMapper.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);

        return new PageInfo<InsureVO>(list, totalPage, pageNo, pageSize);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        insureMapper.deleteAll(ids);
    }
}
